<template>
  <div class="strut-div" id="tourist-place"></div>
</template>
<script>
  import echarts from 'echarts'
  export default {
    name: 'touristPlace',
    mounted() {
      this.chart = echarts.init(document.getElementById('tourist-place'));
      
      this.getMapDataForArea();
    },
    data() {
      return {
        echart: null
      }
    },
    methods: {
      initChart(nameList = [],valueList = []) {
        let option = {
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'shadow'
            }
          },
          grid: {
            left: '3%',
            right: '0%',
            top: '3%',
            bottom: '0%',
            containLabel: true
          },
          xAxis: {
            type: 'value',
            min:0,
            max:function(value) {
                return value.max + 5
            },
            show:false
          },
          yAxis: {
            type: 'category',
             axisLabel:{
                color:'#fff',
                fontSize:12
            },
            data: nameList.reverse()
          },
          series: [
            {
              name: '百分比',
              type: 'bar',
              color: {
                type: 'linear',
                x: 0,
                y: 0,
                x2: 1,
                y2: 0,
                colorStops: [{
                    offset: 0,
                    color: '#2764E2' // 0% 处的颜色
                }, {
                    offset: 1,
                    color: '#62FFEB' // 100% 处的颜色
                }],
              },
              label:{
                  show:true,
                  position:'right',
                  formatter:'{c}%',
                  color:"#62FFEB",
                  fontSize:16
              },
              data: valueList.reverse()
            }
          ]
        };

        this.chart.setOption(option);
      },
      getMapDataForArea() {
            this.$jqGet(this.$api.getMapDataForArea,{
                dataSource: "03",
                objType: "01",
                areaType:"02",
                start: '2019-11-01',
                end: '2019-12-30',
                fjnm: "00010001001400090001"   
            }).then(res => {
                if (res.retCode === 200) {
                    let data = res.retData;
                    let nameList = data.map(item => item.fp_name);
                    let valueList = data.map(item => item.zb);

                    this.initChart(nameList,valueList);
                }
            })
      }
    }
  }

</script>
